package com.yaojiaxun.logisticsPlatformSystem.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yaojiaxun.logisticsPlatformSystem.dto.OrderInfoDTO;
import com.yaojiaxun.logisticsPlatformSystem.entity.OrderInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @Auther: yjx_j
 * @Date: 2019/2/9 18:46
 * @Description:
 */
@Mapper
public interface OrderInfoMapper extends BaseMapper<OrderInfo> {
    @Select("select * from order_info where order_id=#{orderId}")
    public OrderInfo selectOrderById(@Param("orderId") Long orderId);

    @Delete("delete from order_info where order_id=#{orderId}")
    public void deleteOrderById(@Param("orderId") Long orderId);

    @Insert("insert into order_info(order_id, order_client, order_res_province, order_res_city, order_res_country, order_res_address, " +
            "order_des_province, order_des_city, order_des_country, order_des_address, order_goods_name, order_goods_num, " +
            "order_goods_capacity, order_goods_weight, order_remarks, order_com, order_send_person, order_send_person_phone, " +
            "order_receive_person, order_receive_person_phone, order_status, order_reason, create_time, update_time) values (#{orderInfo.orderId}, " +
            "#{orderInfo.orderClient}, #{orderInfo.orderResProvince}, #{orderInfo.orderResCity}, #{orderInfo.orderResCountry}, #{orderInfo.orderResAddress}, " +
            "#{orderInfo.orderDesProvince}, #{orderInfo.orderDesCity}, #{orderInfo.orderDesCountry}, #{orderInfo.orderDesAddress}, " +
            "#{orderInfo.orderGoodsName}, #{orderInfo.orderGoodsNum}, #{orderInfo.orderGoodsCapacity}, #{orderInfo.orderGoodsWeight}, " +
            "#{orderInfo.orderRemarks},#{orderInfo.orderCom}, #{orderInfo.orderSendPerson}, #{orderInfo.orderSendPersonPhone}, " +
            "#{orderInfo.orderReceivePerson}, #{orderInfo.orderReceivePersonPhone}, #{orderInfo.orderStatus}, #{orderInfo.orderReason}, #{orderInfo.createTime}, #{orderInfo.updateTime})")
    public void insertOrderInfo(@Param("orderInfo") OrderInfo orderInfo);

    @Update("update order_info set order_client=#{orderClient}, order_res_province=#{orderResProvince}, order_res_city=#{orderResCity}, order_res_country=#{orderResCountry}, " +
            "order_res_address=#{orderResAddress}, order_des_province=#{orderDesProvince}, order_des_city=#{orderDesCity}, order_des_country=#{orderDesCountry}, " +
            "order_des_address=#{orderDesAddress}, order_goods_name=#{orderGoodsName}, order_goods_num=#{orderGoodsNum}, order_goods_capacity=#{orderGoodsCapacity}, " +
            "order_goods_weight=#{orderGoodsWeight}, order_remarks=#{orderRemarks}, order_com=#{orderCom}, order_send_person=#{orderSendPerson}, " +
            "order_send_person_phone=#{orderSendPersonPhone}, order_receive_person=#{orderReceivePerson}, order_receive_person_phone=#{orderReceivePersonPhone}, " +
            "order_status=#{orderStatus}, order_reason=#{orderReason} where " +
            "order_id=#{orderId}")
    public Integer updateOrderInfoById(@RequestParam("orderInfo") OrderInfo orderInfo);

    @Select("select * from order_info where order_com=#{orderCom}")
    public List<OrderInfo> findOrdersByComName(String orderCom);

//    @Select("select * from order_info where order_client=#{orderClient}")
//    public List<OrderInfo> findOrdersByClientAccount(@Param("orderClient") String orderClient);

    @Select("select * from order_info where order_client=#{orderClient} and order_status='已完成'")
    public List<OrderInfo> findFinishedOrdersByClientAccount(@Param("orderClient") String orderClient);
    @Select("select * from order_info where order_client=#{orderClient} and order_status='未接单'")
    public List<OrderInfo> findUnfinishedOrdersByClientAccount(@Param("orderClient") String orderClient);
    @Select("select * from order_info where order_client=#{orderClient} and order_status='被拒绝'")
    public List<OrderInfo> findRefusedOrdersByClientAccount(@Param("orderClient") String orderAccount);
    @Select("select * from order_info where order_client=#{orderClient} and order_status='已接单'")
    public List<OrderInfo> findReceivedOrdersByClientAccount(@Param("orderClient") String orderAccount);
}
